<!DOCTYPE html>


<html lang="zh-Hans">


<head>
  <meta charset="utf-8" />
   
  <meta name="keywords" content="代码,生活,杂记,思考" />
   
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
  <title>
    对象 |  AURORA
  </title>
  <meta name="generator" content="hexo-theme-ayer">
  
  <link rel="shortcut icon" href="/favicon.ico" />
  
  
<link rel="stylesheet" href="/dist/main.css">

  
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Shen-Yu/cdn/css/remixicon.min.css">

  
<link rel="stylesheet" href="/css/custom.css">

  
  
<script src="https://cdn.jsdelivr.net/npm/pace-js@1.0.2/pace.min.js"></script>

  
  

  

<link rel="alternate" href="/atom.xml" title="AURORA" type="application/atom+xml">
</head>

</html>

<body>
  <div id="app">
    
      
    <main class="content on">
      <section class="outer">
  <article
  id="post-对象"
  class="article article-type-post"
  itemscope
  itemprop="blogPost"
  data-scroll-reveal
>
  <div class="article-inner">
    
    <header class="article-header">
       
<h1 class="article-title sea-center" style="border-left:0" itemprop="name">
  对象
</h1>
 

    </header>
     
    <div class="article-meta">
      <a href="/2020/02/11/%E5%AF%B9%E8%B1%A1/" class="article-date">
  <time datetime="2020-02-10T16:00:00.000Z" itemprop="datePublished">2020-02-11 00:02:00</time>
</a> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/%E6%8A%80%E6%9C%AF/">技术</a> / <a class="article-category-link" href="/categories/%E6%8A%80%E6%9C%AF/%E5%89%8D%E7%AB%AF/">前端</a> / <a class="article-category-link" href="/categories/%E6%8A%80%E6%9C%AF/%E5%89%8D%E7%AB%AF/JavaScript/">JavaScript</a>
  </div>
  
<div class="word_count">
    <span class="post-time">
        <span class="post-meta-item-icon">
            <i class="ri-quill-pen-line"></i>
            <span class="post-meta-item-text"> Word count:</span>
            <span class="post-count">2.1k</span>
        </span>
    </span>

    <span class="post-time">
        &nbsp; | &nbsp;
        <span class="post-meta-item-icon">
            <i class="ri-book-open-line"></i>
            <span class="post-meta-item-text"> Reading time≈</span>
            <span class="post-count">9 min</span>
        </span>
    </span>
</div>
 
    </div>
      
    <div class="tocbot"></div>




  
    <div class="article-entry" itemprop="articleBody">
       
  <h1 id="JavaScript中的对象"><a href="#JavaScript中的对象" class="headerlink" title="JavaScript中的对象"></a>JavaScript中的对象</h1><a id="more"></a>
<h2 id="Object每个实例的方法"><a href="#Object每个实例的方法" class="headerlink" title="Object每个实例的方法"></a>Object每个实例的方法</h2><ol>
<li>constructor：构造函数</li>
<li>hasOwnProperty(propertyname)：检查该属性在对象实例中是否存在<strong>（不检查原型）</strong></li>
<li>isPrototypeOf(obj)：检查传入的对象是不是当前对象的原型</li>
<li>propertyIsEnumerable(propertyname)：检查该属性是否可枚举</li>
<li>toLocalString()，toString()，valueOf()：返回对象的字符串表示/数值表示</li>
</ol>
<h2 id="属性类型——描述属性各种特征"><a href="#属性类型——描述属性各种特征" class="headerlink" title="属性类型——描述属性各种特征"></a>属性类型——描述属性各种特征</h2><p>ES有两大类型属性：数据属性、访问器属性</p>
<ol>
<li><p>数据属性<br> [[configurable]]：能否通过delete删除属性<br> [[enumerable]]：是否可枚举<br> [[writable]]：是否可修改<br> [[value]]：属性值</p>
<p> ES5可以通过使用 <strong>Object.getOwnpropertyDescriptor()</strong> 来获取属性的特征描述<br> 使用 <strong>Object.defineProperty()</strong> 修改默认属性，接收三个参数：属性所在对象、属性名、描述对象</p>
</li>
<li><p>访问器属性<br> [[configurable]]：能否通过delete删除属性<br> [[enumerable]]：是否可枚举<br> [[Get]]：在读取属性时调用，默认为undefine<br> [[Set]]：在写入属性时调用，默认为undefine<br> 常见用途：修改一个属性值时让关联的另一个属性发生变化</p>
</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> book = &#123;</span><br><span class="line">	year:<span class="number">2019</span>,</span><br><span class="line">	edition:<span class="number">1</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">Object</span>.defineProperty(book, <span class="string">'year'</span>, &#123;</span><br><span class="line">	<span class="keyword">get</span>:function()&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="keyword">this</span>.year</span><br><span class="line">	&#125;,</span><br><span class="line">	<span class="keyword">set</span>:function(NewY)&#123;</span><br><span class="line">		<span class="keyword">this</span>.year = NewY</span><br><span class="line">		edition += <span class="number">1</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;)</span><br><span class="line">book.year = <span class="number">2020</span></span><br><span class="line">book.edition  <span class="comment">//2</span></span><br></pre></td></tr></table></figure>
<h2 id="属性名表达式"><a href="#属性名表达式" class="headerlink" title="属性名表达式"></a>属性名表达式</h2><p>ES6允许在使用字面量定义对象时，将表达式作为属性名</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> last = <span class="string">'last'</span></span><br><span class="line"><span class="keyword">var</span> a  = &#123;</span><br><span class="line">   first:<span class="string">'first'</span>,</span><br><span class="line">   [last]:<span class="string">'last'</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(a.first) <span class="comment">//first</span></span><br><span class="line"><span class="built_in">console</span>.log(a[<span class="string">'first'</span>])<span class="comment">//first</span></span><br><span class="line"><span class="built_in">console</span>.log(a.[first])<span class="comment">//error</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">console</span>.log(a.last)<span class="comment">//last</span></span><br><span class="line"><span class="built_in">console</span>.log(a[last])<span class="comment">//last</span></span><br><span class="line"><span class="built_in">console</span>.log(a[<span class="string">'last'</span>])<span class="comment">//last</span></span><br></pre></td></tr></table></figure>
<p>注意：若属性名表达式是一个对象，默认情况下会把属性转换为：[object,object]。一个对象只能有一个对象属性名，多余的会被最后一个覆盖</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> a = &#123;<span class="attr">a</span>:<span class="number">1</span>&#125;</span><br><span class="line"><span class="keyword">const</span> b = &#123;<span class="attr">b</span>:<span class="number">2</span>&#125;</span><br><span class="line"><span class="keyword">const</span> c = &#123;</span><br><span class="line">	[a]:<span class="number">1</span>,</span><br><span class="line">	[b]:<span class="number">2</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(c)</span><br><span class="line"><span class="comment">//&#123;[object,object]:2&#125;</span></span><br></pre></td></tr></table></figure>
<h2 id="方法的name属性"><a href="#方法的name属性" class="headerlink" title="方法的name属性"></a>方法的name属性</h2><p>该属性是函数的属性，返回函数名</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> p = &#123;</span><br><span class="line">	sayname()&#123;</span><br><span class="line">		<span class="built_in">console</span>.log(<span class="string">'tom'</span>)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">console</span>.log(p.sayname.name)<span class="comment">//sayname</span></span><br></pre></td></tr></table></figure>
<p>对于用bind产生的函数，会在名字前加上“bound”</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> fun = <span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;...&#125;</span><br><span class="line"><span class="built_in">console</span>.log(fun.bind().name)<span class="comment">//"bound fun"</span></span><br></pre></td></tr></table></figure>
<h2 id="Object-is"><a href="#Object-is" class="headerlink" title="Object.is()"></a>Object.is()</h2><p>用同值相等算法比较两个值<strong>严格相等</strong><br>对于es5中的 “ == ”  和  “ === ”，前者会自动转换数据类型，后者NaN不等于自身，因此ES6提供了新方法判断两个值严格相等</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Object</span>.is(<span class="string">'foo'</span>,<span class="string">'foo'</span>)<span class="comment">//true</span></span><br><span class="line"><span class="built_in">Object</span>.is(&#123;&#125;,&#123;&#125;)<span class="comment">//false</span></span><br><span class="line"></span><br><span class="line">+<span class="number">0</span> === <span class="number">-0</span> <span class="comment">//true</span></span><br><span class="line"><span class="built_in">Object</span>.is(+<span class="number">0</span>, <span class="number">-0</span>) <span class="comment">// false</span></span><br><span class="line"><span class="literal">NaN</span> === <span class="literal">NaN</span> <span class="comment">//false</span></span><br><span class="line"><span class="built_in">Object</span>.is(<span class="literal">NaN</span>, <span class="literal">NaN</span>) <span class="comment">//true</span></span><br></pre></td></tr></table></figure>
<h2 id="Object-assign"><a href="#Object-assign" class="headerlink" title="Object.assign()"></a>Object.assign()</h2><p>将源对象所有可枚举属性复制到目标对象，第一个参数是目标对象， 后面所有参数都是源对象。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> target = &#123;<span class="attr">a</span>:<span class="number">1</span>&#125;</span><br><span class="line"><span class="keyword">var</span> source = &#123;<span class="attr">b</span>:<span class="number">2</span>&#125;</span><br><span class="line"><span class="built_in">Object</span>.assign(target, source)</span><br><span class="line"><span class="comment">//target:</span></span><br><span class="line"><span class="comment">//&#123;a:1, b:2&#125;</span></span><br></pre></td></tr></table></figure>
<p>当目标对象与源对象有重名属性，或多个源对象之间有重名属性，则后面的属性会覆盖之前的属性。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> target = &#123;<span class="attr">a</span>:<span class="number">1</span>&#125;</span><br><span class="line"><span class="keyword">var</span> source = &#123;<span class="attr">b</span>:<span class="number">2</span>&#125;</span><br><span class="line"><span class="keyword">var</span> source1 = &#123;<span class="attr">b</span>:<span class="number">3</span>&#125;</span><br><span class="line"><span class="built_in">Object</span>.assign(target, source, source1)</span><br><span class="line"><span class="comment">//target:</span></span><br><span class="line"><span class="comment">//&#123;a:1, b:3&#125;</span></span><br></pre></td></tr></table></figure>
<h3 id="对于Object-assign-的参数"><a href="#对于Object-assign-的参数" class="headerlink" title="对于Object.assign()的参数"></a>对于Object.assign()的参数</h3><ol>
<li>只有一个参数，直接返回参数</li>
<li>该参数不是对象，则转化为对象</li>
<li>参数为undefine或null，报错</li>
<li>非对象出现在非首参数（源对象）位置，只有字符串会以数组形式复制到目标对象当中，其他值无效<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> v1 = <span class="string">'abc'</span></span><br><span class="line"><span class="keyword">var</span> obj = <span class="built_in">Object</span>.assign(&#123;&#125;, v1)</span><br><span class="line"><span class="comment">//&#123;0:'a', 1:'b', 2:'c'&#125;</span></span><br></pre></td></tr></table></figure>
<strong>注意：该方法不复制对象的继承属性和不可枚举属性</strong><br>该方法使用的是<strong>浅复制</strong></li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj1 = &#123;<span class="attr">a</span>:<span class="number">1</span>&#125;</span><br><span class="line"><span class="keyword">var</span> obj2 = <span class="built_in">Object</span>.assign(&#123;&#125;, obj1)</span><br><span class="line">obj2 <span class="comment">//&#123;a:1&#125;</span></span><br><span class="line">obj1.a.b = <span class="number">3</span></span><br><span class="line">obj2 <span class="comment">//&#123;a:&#123;b:3&#125;&#125;</span></span><br><span class="line"><span class="comment">//obj2得到的是obj1的引用</span></span><br></pre></td></tr></table></figure>
<h3 id="应用于数组"><a href="#应用于数组" class="headerlink" title="应用于数组"></a>应用于数组</h3><p>既然数组实际上是对象，数组实际的存储是这样的<br>{<br>    ‘1’ : ‘a ,<br>    ‘2’ : ‘b’,<br>    ‘3’ : ‘c’<br>}<br>所以对于数组的处理就比较特殊</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Object</span>.assign([<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>], [<span class="number">4</span>, <span class="number">5</span>]) </span><br><span class="line"><span class="comment">//[4, 5, 3]</span></span><br></pre></td></tr></table></figure>
<h3 id="Object-assign的用途"><a href="#Object-assign的用途" class="headerlink" title="Object.assign的用途"></a>Object.assign的用途</h3><ol>
<li>给对象添加属性</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">point</span></span>&#123;</span><br><span class="line">	<span class="keyword">constructor</span>(x, y)&#123;</span><br><span class="line">		<span class="built_in">Object</span>.assign(<span class="keyword">this</span>, &#123;x, y&#125;)</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ol start="2">
<li>给对象添加方法</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;&#125;</span><br><span class="line"><span class="built_in">Object</span>.assign(obj.prototype, &#123;</span><br><span class="line">	fun1(arg)&#123;...&#125;,</span><br><span class="line">	fun2(arg)&#123;...&#125;,</span><br><span class="line">	...</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
<ol start="3">
<li>克隆对象</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clone</span>(<span class="params">obj</span>)</span>&#123;</span><br><span class="line">	<span class="keyword">return</span> <span class="built_in">Object</span>.assign(&#123;&#125;, obj)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//若要连带拷贝其继承属性</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">clone</span>(<span class="params">obj</span>)</span>&#123;</span><br><span class="line">	<span class="keyword">var</span> proto = obj.__proto__</span><br><span class="line">	<span class="keyword">return</span> <span class="built_in">Object</span>.assign(&#123;&#125;, <span class="built_in">Object</span>.create(proto, obj))</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<ol start="4">
<li>合并多个对象</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> merge = <span class="function">(<span class="params">...sou</span>) =&gt;</span> &#123;<span class="keyword">return</span> <span class="built_in">Object</span>.assign(&#123;&#125;, ...sou)&#125;</span><br></pre></td></tr></table></figure>
<ol start="5">
<li>为属性指定默认值</li>
</ol>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">const</span> <span class="keyword">default</span> = &#123;<span class="attr">a</span>:<span class="number">1</span>, <span class="attr">b</span>:<span class="number">2</span>&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fun</span>(<span class="params">option</span>)</span>&#123;</span><br><span class="line">	<span class="built_in">Object</span>.assign(&#123;&#125;, <span class="keyword">default</span>, option)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="属性的描述对象"><a href="#属性的描述对象" class="headerlink" title="属性的描述对象"></a>属性的描述对象</h2><p>前面已经提到， ES5可以通过使用 <strong>Object.getOwnpropertyDescriptor()</strong> 来获取属性的特征描述</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;<span class="attr">foo</span>: <span class="number">123</span>&#125;</span><br><span class="line"><span class="built_in">Object</span>.getOwnPropertyDescriptor(obj, <span class="string">'foo'</span>)</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">&#123;</span></span><br><span class="line"><span class="comment">	value:123,</span></span><br><span class="line"><span class="comment">	writable:true,</span></span><br><span class="line"><span class="comment">	enumerable:true,</span></span><br><span class="line"><span class="comment">	configurable:true</span></span><br><span class="line"><span class="comment">&#125;</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<p>ES6规定：所有class的原型方法都是不可枚举的</p>
<p>ES6提供了<strong>Object.getOwnpropertyDescriptor()</strong>，返回所有对象属性的描述对象</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">	foo:<span class="number">123</span>,</span><br><span class="line">	<span class="keyword">get</span> fun()&#123;</span><br><span class="line">		<span class="keyword">return</span> <span class="string">'abc'</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">Object</span>.getOwnpropertyDescriptors(obj)</span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">&#123;</span></span><br><span class="line"><span class="comment">	foo:&#123;</span></span><br><span class="line"><span class="comment">		value:123,</span></span><br><span class="line"><span class="comment">		writable:true,</span></span><br><span class="line"><span class="comment">		enumerable:true,</span></span><br><span class="line"><span class="comment">		configurable:true</span></span><br><span class="line"><span class="comment">	&#125;,</span></span><br><span class="line"><span class="comment">	fun:&#123;</span></span><br><span class="line"><span class="comment">		get:[Function:fun],</span></span><br><span class="line"><span class="comment">		set:undefine,</span></span><br><span class="line"><span class="comment">		enumerable:true,</span></span><br><span class="line"><span class="comment">		configurable:true</span></span><br><span class="line"><span class="comment">	&#125;</span></span><br><span class="line"><span class="comment">&#125;</span></span><br><span class="line"><span class="comment">*/</span></span><br></pre></td></tr></table></figure>
<h2 id="属性的遍历"><a href="#属性的遍历" class="headerlink" title="属性的遍历"></a>属性的遍历</h2><ol>
<li>for…in：遍历自身和继承的所有可继承属性</li>
<li>Object.key(obj)：返回数组，包含对象<strong>自身的所有可枚举属性</strong></li>
<li>Object.getOwnPropertyName(obj)：返回数组，包含<strong>对象自身所有属性（不含symbol）</strong></li>
<li>Object.getOwnPropertySymbol(obj)：返回数组，包含<strong>对象自身所有symbol属性</strong></li>
<li><p>Reflect.OwnKeys(obj)：返回数组，包含<strong>对象自身所有属性</strong></p>
<p>这些遍历对象属性的方法均遵守：</p>
</li>
<li>属性名为数字，按数字排序</li>
<li>属性名为字符串或symbol，按生成顺序排序</li>
<li>若三者混合，则按数字 -&gt; 字符串 -&gt; symbol排序</li>
</ol>
<h3 id="Object-key"><a href="#Object-key" class="headerlink" title="Object.key()"></a>Object.key()</h3><p>es5引入的该方法，返回一个数组，成员是参数自身的所有可枚举属性的<strong>键名</strong></p>
<h3 id="Object-values"><a href="#Object-values" class="headerlink" title="Object.values()"></a>Object.values()</h3><p>返回一个数组，成员是参数自身的所有可遍历属性属性的<strong>键值</strong></p>
<h3 id="Object-entries"><a href="#Object-entries" class="headerlink" title="Object.entries()"></a>Object.entries()</h3><p>返回一个数组，成员是参数自身的所有克遍历属性的<strong>键值对数组</strong></p>
<h2 id="“-proto-“"><a href="#“-proto-“" class="headerlink" title="“ proto “"></a>“<strong> proto </strong>“</h2><p>用来读取设置当前对象的prototype对象。<br>注意：这不是一个正式的对外开放的API，只不过广大浏览器支持了这个属性。<br>一般建议使用<strong>Object.getPrototypeOf()</strong></p>
<h2 id="Object-getPrototypeOf-和Object-setPrototypeOf"><a href="#Object-getPrototypeOf-和Object-setPrototypeOf" class="headerlink" title="Object.getPrototypeOf()和Object.setPrototypeOf()"></a>Object.getPrototypeOf()和Object.setPrototypeOf()</h2><p>ES6推荐使用Object.setPrototypeOf()设置对象的原型，使用Object.getPrototypeOf()读取对象原型<br>关于后者的参数</p>
<ol>
<li>若是Number，String，boolean，则之间返回参数</li>
<li>若是undefine，null，则报错</li>
</ol>
<h2 id="对象的扩展运算符"><a href="#对象的扩展运算符" class="headerlink" title="对象的扩展运算符"></a>对象的扩展运算符</h2><h3 id="对象的解构赋值"><a href="#对象的解构赋值" class="headerlink" title="对象的解构赋值"></a>对象的解构赋值</h3><p>将对象可遍历却又未读取的属性分配到指定的对象上面</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> &#123;x, y, ...z&#125; = &#123;<span class="attr">x</span>:<span class="number">1</span>, <span class="attr">y</span>:<span class="number">2</span>, <span class="attr">a</span>:<span class="number">3</span>, <span class="attr">b</span>:<span class="number">4</span>, <span class="attr">c</span>:<span class="number">5</span>&#125;</span><br><span class="line">x<span class="comment">//1</span></span><br><span class="line">y<span class="comment">//2</span></span><br><span class="line">z<span class="comment">//&#123;a:1, b:2, c:3&#125;</span></span><br></pre></td></tr></table></figure>
<p>解构赋值等号右边不能是undefine或null，否则直接报错</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> &#123;x, y, ...z&#125; = undefine</span><br><span class="line"><span class="keyword">var</span> &#123;x, y, ...z&#125; = <span class="literal">null</span></span><br><span class="line"><span class="comment">//统统报错</span></span><br></pre></td></tr></table></figure>
<p>注意：结构赋值的复制过程是浅复制，如果一个键的值是引用类型，那么解构赋值得到的是这个值的引用，同时，结构赋值也不会赋值继承自原型对象的属性</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;<span class="attr">a</span>:<span class="number">1</span>, <span class="attr">b</span>:<span class="number">2</span>&#125;</span><br><span class="line"><span class="keyword">var</span> a = &#123;...obj&#125;</span><br><span class="line">obj.a = <span class="number">5</span></span><br><span class="line"><span class="built_in">console</span>.log(a)</span><br><span class="line"><span class="comment">//1</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> obj1 = &#123;<span class="attr">a</span>:<span class="number">1</span>, <span class="attr">b</span>:<span class="number">2</span>, <span class="attr">c</span>:&#123;<span class="attr">d</span>:<span class="number">3</span>&#125;&#125;</span><br><span class="line"><span class="keyword">var</span> b = &#123;...obj1&#125;</span><br><span class="line">obj1.c.d = <span class="number">6</span></span><br><span class="line"><span class="built_in">console</span>.log(b)</span><br><span class="line"><span class="comment">//&#123;a:1, b:2, c:&#123;d:6&#125;&#125;</span></span><br></pre></td></tr></table></figure>
<h3 id="取出参数对象所有可遍历属性"><a href="#取出参数对象所有可遍历属性" class="headerlink" title="取出参数对象所有可遍历属性"></a>取出参数对象所有可遍历属性</h3><p>类似于Object.assign()的操作，也不能复制其继承属性<br><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> z  =&#123;<span class="attr">a</span>:<span class="number">3</span>, <span class="attr">b</span>:<span class="number">4</span>&#125;</span><br><span class="line"><span class="keyword">let</span> k = &#123;...z&#125;</span><br><span class="line"><span class="comment">//k:&#123;a:3, b:4&#125;</span></span><br></pre></td></tr></table></figure><br>稍作改进也可以复制其继承属性</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> z  =&#123;<span class="attr">a</span>:<span class="number">3</span>, <span class="attr">b</span>:<span class="number">4</span>&#125;</span><br><span class="line"><span class="keyword">let</span> k = &#123;...Object.create(<span class="built_in">Object</span>.getPrototypeOf(z)),...z&#125;</span><br></pre></td></tr></table></figure>
<p>他有和Object.assign()类似的作用</p>
<h4 id="克隆对象"><a href="#克隆对象" class="headerlink" title="克隆对象"></a>克隆对象</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> z  =&#123;<span class="attr">a</span>:<span class="number">3</span>, <span class="attr">b</span>:<span class="number">4</span>&#125;</span><br><span class="line">z.__proto__.name = <span class="string">'z'</span></span><br><span class="line"><span class="keyword">let</span> k = &#123;...Object.create(<span class="built_in">Object</span>.getPrototypeOf(z)),...z&#125;</span><br><span class="line"><span class="built_in">console</span>.log(z)</span><br><span class="line"><span class="built_in">console</span>.log(k)</span><br></pre></td></tr></table></figure>
<p><img src="https://img-blog.csdnimg.cn/20200211204539680.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3UwMTIwMzE5NTg=,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h4 id="合并对象"><a href="#合并对象" class="headerlink" title="合并对象"></a>合并对象</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> a = &#123;<span class="attr">x</span>:<span class="number">1</span>&#125;</span><br><span class="line"><span class="keyword">let</span> b = &#123;<span class="attr">y</span>:<span class="number">2</span>&#125;</span><br><span class="line"><span class="keyword">let</span> ab = &#123;...a, ...b&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//等价于</span></span><br><span class="line"><span class="keyword">let</span> ab = <span class="built_in">Object</span>.assign(&#123;&#125;, a, b)</span><br></pre></td></tr></table></figure>
<p>扩展运算符后面的属性值会覆盖扩展运算符中的同名属性，同assign</p>
<h4 id="添加默认值"><a href="#添加默认值" class="headerlink" title="添加默认值"></a>添加默认值</h4><p>将用户定义的默认值放在运算符前面，就可以为对象设置默认值</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> <span class="keyword">default</span> = &#123;<span class="attr">x</span>:<span class="number">1</span>, <span class="attr">y</span>:<span class="number">2</span>, ...a&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//等同于</span></span><br><span class="line"><span class="keyword">let</span> <span class="keyword">default</span> = <span class="built_in">Object</span>.assign(&#123;&#125;, &#123;<span class="attr">x</span>:<span class="number">1</span>, <span class="attr">y</span>:<span class="number">2</span>&#125;, a)</span><br></pre></td></tr></table></figure>
<p>对象的扩展运算符后面可以带有表达式</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> obj = &#123;</span><br><span class="line">	...(x &gt; <span class="number">1</span> ? &#123;<span class="attr">x</span>:<span class="number">1</span>&#125; : &#123;<span class="attr">y</span>:<span class="number">2</span>&#125;),</span><br><span class="line">	b:<span class="number">2</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>对象扩展运算符的参数为null或undefine时，这两个值会被忽略，不会报错</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> a</span><br><span class="line"><span class="keyword">var</span> b = <span class="literal">null</span></span><br><span class="line"><span class="keyword">var</span> c = &#123;...a&#125;</span><br><span class="line"><span class="keyword">var</span> d = &#123;...b&#125;</span><br><span class="line"><span class="comment">//均不报错</span></span><br></pre></td></tr></table></figure>
 
      <!-- reward -->
      
    </div>
    

    <!-- copyright -->
    
    <div class="declare">
      <ul class="post-copyright">
        <li>
          <i class="ri-copyright-line"></i>
          <strong>Copyright： </strong>
          Copyright is owned by the author. For commercial reprints, please contact the author for authorization. For non-commercial reprints, please indicate the source.
        </li>
      </ul>
    </div>
    
    <footer class="article-footer">
       
<div class="share-btn">
      <span class="share-sns share-outer">
        <i class="ri-share-forward-line"></i>
        分享
      </span>
      <div class="share-wrap">
        <i class="arrow"></i>
        <div class="share-icons">
          
          <a class="weibo share-sns" href="javascript:;" data-type="weibo">
            <i class="ri-weibo-fill"></i>
          </a>
          <a class="weixin share-sns wxFab" href="javascript:;" data-type="weixin">
            <i class="ri-wechat-fill"></i>
          </a>
          <a class="qq share-sns" href="javascript:;" data-type="qq">
            <i class="ri-qq-fill"></i>
          </a>
          <a class="douban share-sns" href="javascript:;" data-type="douban">
            <i class="ri-douban-line"></i>
          </a>
          <!-- <a class="qzone share-sns" href="javascript:;" data-type="qzone">
            <i class="icon icon-qzone"></i>
          </a> -->
          
          <a class="facebook share-sns" href="javascript:;" data-type="facebook">
            <i class="ri-facebook-circle-fill"></i>
          </a>
          <a class="twitter share-sns" href="javascript:;" data-type="twitter">
            <i class="ri-twitter-fill"></i>
          </a>
          <a class="google share-sns" href="javascript:;" data-type="google">
            <i class="ri-google-fill"></i>
          </a>
        </div>
      </div>
</div>

<div class="wx-share-modal">
    <a class="modal-close" href="javascript:;"><i class="ri-close-circle-line"></i></a>
    <p>扫一扫，分享到微信</p>
    <div class="wx-qrcode">
      <img src="" alt="微信分享二维码">
    </div>
</div>

<div id="share-mask"></div>  
    </footer>
  </div>

   
  <nav class="article-nav">
    
      <a href="/2020/02/12/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%9A%84%E7%A8%8B%E5%BA%8F%E8%AE%BE%E8%AE%A1/" class="article-nav-link">
        <strong class="article-nav-caption">上一篇</strong>
        <div class="article-nav-title">
          
            面向对象的程序设计
          
        </div>
      </a>
    
    
      <a href="/2020/02/11/%E4%BA%8B%E4%BB%B6/" class="article-nav-link">
        <strong class="article-nav-caption">下一篇</strong>
        <div class="article-nav-title">事件</div>
      </a>
    
  </nav>

   
<!-- valine评论 -->
<div id="vcomments-box">
  <div id="vcomments"></div>
</div>
<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/valine@1.4.14/dist/Valine.min.js"></script>
<script>
  new Valine({
    el: "#vcomments",
    app_id: "2eBxdPB3eEwraN7IpwFckzeL-gzGzoHsz",
    app_key: "VGgCefQEluVxHdyMsm1Dpeih",
    path: window.location.pathname,
    avatar: "monsterid",
    placeholder: "评论一下我的文章吧~",
    recordIP: true,
  });
  const infoEle = document.querySelector("#vcomments .info");
  if (infoEle && infoEle.childNodes && infoEle.childNodes.length > 0) {
    infoEle.childNodes.forEach(function (item) {
      item.parentNode.removeChild(item);
    });
  }
</script>
<style>
  #vcomments-box {
    padding: 5px 30px;
  }

  @media screen and (max-width: 800px) {
    #vcomments-box {
      padding: 5px 0px;
    }
  }

  #vcomments-box #vcomments {
    background-color: #fff;
  }

  .v .vlist .vcard .vh {
    padding-right: 20px;
  }

  .v .vlist .vcard {
    padding-left: 10px;
  }
</style>

 
     
</article>

</section>
      <footer class="footer">
  <div class="outer">
    <ul>
      <li>
        Copyrights &copy;
        2015-2020
        <i class="ri-heart-fill heart_icon"></i> AURORA_ZXH
      </li>
    </ul>
    <ul>
      <li>
        
        
        
        Powered by <a href="https://hexo.io" target="_blank">Hexo</a>
        <span class="division">|</span>
        Theme - <a href="https://github.com/Shen-Yu/hexo-theme-ayer" target="_blank">Ayer</a>
        
      </li>
    </ul>
    <ul>
      <li>
        
        
        <span>
  <span><i class="ri-user-3-fill"></i>Visitors:<span id="busuanzi_value_site_uv"></span></s>
  <span class="division">|</span>
  <span><i class="ri-eye-fill"></i>Views:<span id="busuanzi_value_page_pv"></span></span>
</span>
        
      </li>
    </ul>
    <ul>
      
    </ul>
    <ul>
      <li>
        <!-- cnzz统计 -->
        
        <script type="text/javascript" src='https://s9.cnzz.com/z_stat.php?id=1278069914&amp;web_id=1278069914'></script>
        
      </li>
    </ul>
  </div>
</footer>
      <div class="float_btns">
        <div class="totop" id="totop">
  <i class="ri-arrow-up-line"></i>
</div>

<div class="todark" id="todark">
  <i class="ri-moon-line"></i>
</div>

      </div>
    </main>
    <aside class="sidebar on">
      <button class="navbar-toggle"></button>
<nav class="navbar">
  
  <div class="logo">
    <a href="/"><img src="/images/avatar.jpg" alt="AURORA"></a>
  </div>
  
  <ul class="nav nav-main">
    
    <li class="nav-item">
      <a class="nav-item-link" href="/">主页</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/archives">归档</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/categories">分类</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/tags">标签</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="http://aurora-zxh.lofter.com/" target="_blank" rel="noopener">随记</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/about">关于我</a>
    </li>
    
    <li class="nav-item">
      <a class="nav-item-link" href="/link">友链</a>
    </li>
    
  </ul>
</nav>
<nav class="navbar navbar-bottom">
  <ul class="nav">
    <li class="nav-item">
      
      <a class="nav-item-link nav-item-search"  title="Search">
        <i class="ri-search-line"></i>
      </a>
      
      
      <a class="nav-item-link" target="_blank" href="/atom.xml" title="RSS Feed">
        <i class="ri-rss-line"></i>
      </a>
      
    </li>
  </ul>
</nav>
<div class="search-form-wrap">
  <div class="local-search local-search-plugin">
  <input type="search" id="local-search-input" class="local-search-input" placeholder="Search...">
  <div id="local-search-result" class="local-search-result"></div>
</div>
</div>
    </aside>
    <script>
      if (window.matchMedia("(max-width: 768px)").matches) {
        document.querySelector('.content').classList.remove('on');
        document.querySelector('.sidebar').classList.remove('on');
      }
    </script>
    <div id="mask"></div>

<!-- #reward -->
<div id="reward">
  <span class="close"><i class="ri-close-line"></i></span>
  <p class="reward-p"><i class="ri-cup-line"></i>请我喝杯咖啡吧~</p>
  <div class="reward-box">
    
    <div class="reward-item">
      <img class="reward-img" src="/images/alipay.png">
      <span class="reward-type">支付宝</span>
    </div>
    
    
    <div class="reward-item">
      <img class="reward-img" src="/images/wxpay.png">
      <span class="reward-type">微信</span>
    </div>
    
  </div>
</div>
    
<script src="/js/jquery-2.0.3.min.js"></script>


<script src="/js/lazyload.min.js"></script>

<!-- Tocbot -->


<script src="/js/tocbot.min.js"></script>

<script>
  tocbot.init({
    tocSelector: '.tocbot',
    contentSelector: '.article-entry',
    headingSelector: 'h1, h2, h3, h4, h5, h6',
    hasInnerContainers: true,
    scrollSmooth: true,
    scrollContainer: 'main',
    positionFixedSelector: '.tocbot',
    positionFixedClass: 'is-position-fixed',
    fixedSidebarOffset: 'auto'
  });
</script>

<script src="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/jquery-modal@0.9.2/jquery.modal.min.css">
<script src="https://cdn.jsdelivr.net/npm/justifiedGallery@3.7.0/dist/js/jquery.justifiedGallery.min.js"></script>

<script src="/dist/main.js"></script>

<!-- ImageViewer -->

<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">

    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>

    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">

        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>

        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">

            <div class="pswp__top-bar">

                <!--  Controls are self-explanatory. Order can be changed. -->

                <div class="pswp__counter"></div>

                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>

                <button class="pswp__button pswp__button--share" style="display:none" title="Share"></button>

                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>

                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>

                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                        <div class="pswp__preloader__cut">
                            <div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div>
            </div>

            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>

            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>

            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>

        </div>

    </div>

</div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/default-skin/default-skin.min.css">
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/photoswipe@4.1.3/dist/photoswipe-ui-default.min.js"></script>

<script>
    function viewer_init() {
        let pswpElement = document.querySelectorAll('.pswp')[0];
        let $imgArr = document.querySelectorAll(('.article-entry img:not(.reward-img)'))

        $imgArr.forEach(($em, i) => {
            $em.onclick = () => {
                // slider展开状态
                // todo: 这样不好，后面改成状态
                if (document.querySelector('.left-col.show')) return
                let items = []
                $imgArr.forEach(($em2, i2) => {
                    let img = $em2.getAttribute('data-idx', i2)
                    let src = $em2.getAttribute('data-target') || $em2.getAttribute('src')
                    let title = $em2.getAttribute('alt')
                    // 获得原图尺寸
                    const image = new Image()
                    image.src = src
                    items.push({
                        src: src,
                        w: image.width || $em2.width,
                        h: image.height || $em2.height,
                        title: title
                    })
                })
                var gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, {
                    index: parseInt(i)
                });
                gallery.init()
            }
        })
    }
    viewer_init()
</script>

<!-- MathJax -->

<!-- Katex -->

<!-- busuanzi  -->


<script src="/js/busuanzi-2.3.pure.min.js"></script>


<!-- ClickLove -->

<!-- ClickBoom1 -->

<!-- ClickBoom2 -->

<!-- CodeCopy -->


<link rel="stylesheet" href="/css/clipboard.css">

<script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script>
  function wait(callback, seconds) {
    var timelag = null;
    timelag = window.setTimeout(callback, seconds);
  }
  !function (e, t, a) {
    var initCopyCode = function(){
      var copyHtml = '';
      copyHtml += '<button class="btn-copy" data-clipboard-snippet="">';
      copyHtml += '<i class="ri-file-copy-2-line"></i><span>COPY</span>';
      copyHtml += '</button>';
      $(".highlight .code pre").before(copyHtml);
      $(".article pre code").before(copyHtml);
      var clipboard = new ClipboardJS('.btn-copy', {
        target: function(trigger) {
          return trigger.nextElementSibling;
        }
      });
      clipboard.on('success', function(e) {
        let $btn = $(e.trigger);
        $btn.addClass('copied');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-checkbox-circle-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPIED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-checkbox-circle-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
      clipboard.on('error', function(e) {
        e.clearSelection();
        let $btn = $(e.trigger);
        $btn.addClass('copy-failed');
        let $icon = $($btn.find('i'));
        $icon.removeClass('ri-file-copy-2-line');
        $icon.addClass('ri-time-line');
        let $span = $($btn.find('span'));
        $span[0].innerText = 'COPY FAILED';
        
        wait(function () { // 等待两秒钟后恢复
          $icon.removeClass('ri-time-line');
          $icon.addClass('ri-file-copy-2-line');
          $span[0].innerText = 'COPY';
        }, 2000);
      });
    }
    initCopyCode();
  }(window, document);
</script>


<!-- CanvasBackground -->


    
  </div>
</body>

</html>